//
// Created by 25313 on 2025/8/6.
//
class Solution {
public:
    long long maximumProduct(vector<int>& nums, int m) {
        int size = nums.size();
        int minNUM = INT_MAX, maxNUM = INT_MIN;
        long long res = LLONG_MIN;
        if(m == 1){
            for(int num : nums)
            {
                res = max(res, (long long)num * num);
            }
        }
        else{
            for(int i = m - 1; i < size; i++)
            {
                int start = nums[i - m + 1];
                int end = nums[i];
                minNUM = min(minNUM,start);
                maxNUM = max(maxNUM,start);
                res = max(res,(long long)end * minNUM);
                res = max(res,(long long)end * maxNUM);
            }
        }
        return res;
    }